package s1.s1_4.combo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/*
ID: huangmingbo
LANG: JAVA
TASK: combo
 */
public class combo {
    public static void main(String[] args) throws IOException {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(combo.class.getResourceAsStream(combo.class.getSimpleName() + ".in")));
                PrintWriter writer = new PrintWriter(new PrintWriter(combo.class.getSimpleName() + ".out"));
        ) {

            int N = Integer.parseInt(reader.readLine());
            StringTokenizer stringTokenizer = new StringTokenizer(reader.readLine());
            int[] arr1 = new int[]{Integer.parseInt(stringTokenizer.nextToken()), Integer.parseInt(stringTokenizer.nextToken()), Integer.parseInt(stringTokenizer.nextToken())};
            stringTokenizer = new StringTokenizer(reader.readLine());
            int[] arr2 = new int[]{Integer.parseInt(stringTokenizer.nextToken()), Integer.parseInt(stringTokenizer.nextToken()), Integer.parseInt(stringTokenizer.nextToken())};


            int count = 0;
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    for (int k = 1; k <= N; k++) {
                        if (nearBy(i, j, k, arr1, arr2, N)) {
                            count++;
                        }
                    }
                }
            }

            writer.println(count);
        }

    }

    private static boolean nearBy(int i, int j, int k, int[] arr1, int[] arr2, int N) {
        return nearBy(i, j, k, arr1, N) || nearBy(i, j, k, arr2, N);
    }

    private static boolean nearBy(int i, int j, int k, int[] arr1, int N) {

        return (Math.abs(i - arr1[0]) <= 2 || Math.abs(i - arr1[0]) >= N - 2)
                && (Math.abs(j - arr1[1]) <= 2 || Math.abs(j - arr1[1]) >= N - 2)
                && (Math.abs(k - arr1[2]) <= 2 || Math.abs(k - arr1[2]) >= N - 2);
    }
}
